function module(context,settings) {
	this.cotext = context;
	this._row_temp = settings.row_temp?settings.row_temp:null ;
	this._c =  settings.c?settings.c:0;
    this._row= settings.row?settings.row:true;
    this._callFunc = null;
    
}

module.prototype = {
		
    constructor: module,
    
    drawModule : function( type, module,rows) {

		if (this._row) {
			
			if (this._c == 0) {

				this._row_temp = $(t_module.row_temp);
				this.cotext.append(this._row_temp);
			}
			this._c++;

			this._row_temp.append(module);

			if (this._c == rows) {
				this._c = 0;
			}

		} else {

			this.cotext.append(module);

		}

	},
	/**
	 * {row:ture
	 *  ,rows:
	 * ,texts:[
	 * {key
	 * ,name
	 * ,value}]
	 * ,drawtype}
	 */
	labelText : function( text_def) {

		var rows;
		this._row_temp=null;
		this._c=0;

		if (text_def._row==false){
			this._row = false
		}else{
			rows=text_def.rows?text_def.rows:4;
		}
		
		var texts = text_def.texts;
		var type = text_def.drawtype;
		
		if(type=="replace"){
			
			this.cotext.empty();
			
		}

		for ( var i in texts) {

			if (!texts[i].value) {
				texts[i].value = "";
			}

			var module = hereDoc(t_module.labelText_temp, texts[i]);

			this.drawModule( type, module,rows)
			
		}

	},
	/**
	 * {
	 * ,forms:[
	 * {key
	 * ,name
	 * ,value
	 * ,type
	 * ,dataSource
	 * ,dateType}]
	 * ,drawtype
	 * ,row
	 * ,rows
	 * }
	 */
	form : function( form_def) {
		
		var rows;
		this._row_temp=null;
		this._c=0;

		if (form_def._row==false){
			this._row = false
		}else{
			rows=form_def.rows?form_def.rows:3;
		}
		
		var forms = form_def.forms;
		var type = form_def.drawtype;
		
		if(type=="replace"){
			
			this.cotext.empty();
			
		}

		for ( var i in forms) {

			if (!forms[i].value) {
				forms[i].value = "";
			}
			
			var module;
			
			forms[i].module = "f_"

			if (forms[i].type == 'select') {

				module = hereDoc(t_module.f_select_temp, forms[i]);

				this.callFunc = t_module.doSelect;

			} else if (forms[i].type == 'time') {

				module = hereDoc(t_module.f_time_temp, forms[i]);

				this.callFunc = t_module.doformTime;

			} else {

				module = hereDoc(t_module.f_input_temp, forms[i]);

				this.callFunc = null;

			}

			this.drawModule( type, module,rows)
			
			if(this.callFunc){
			callFunc(forms[i])
			}
			
		}
		
		

	},
	/**
	 * {
	 * ,query:[
	 * {key
	 * ,name
	 * ,value
	 * ,type
	 * ,dataSource
	 * ,dateType}]
	 * ,buttons:[
	 * name
	 * ,key
	 * ,layout
	 * ,func
	 * ,addclass
	 * ,style
	 * ]
	 * ,drawtype}
	 */
	query : function(query_def) {
		
		var rows;
		this._row_temp=null;
		this._c=0;

		if (query_def._row==false){
			this._row = false
		}else{
			rows=query_def.rows?query_def.rows:3;
		}
		
		var querys = query_def.forms;
		var type = query_def.drawtype;
		
		if(type=="replace"){
			
			this.cotext.empty();
			
		}

		for ( var i in querys) {

			if (!querys[i].value) {
				querys[i].value = "";
			}
			
			var module;
			
			querys[i].module = "q_"

			if (querys[i].type == 'select') {

				module = hereDoc(t_module.q_select_temp, querys[i]);

				this.callFunc = t_module.doSelect;

			} else if (querys[i].type == 'time') {

				module = hereDoc(t_module.q_time_temp, querys[i]);

				this.callFunc = t_module.doQueryTime;

			} else {

				module = hereDoc(t_module.q_input_temp, querys[i]);

				this.callFunc = null;  

			}

			this.drawModule( type, module,rows)
			
			
			if(this.callFunc){
				this.callFunc(querys[i])
			}
			
		}
		
		
		

	},
	modal : function(modal_def) {

	},
	
	/**
	 * grid_def:
	 * {
	 * 必要参数：
	 * url:,
	 * colModel: [{sortable:false
	 * ,label : '仓库编号'
	 * ,name :'whCode'
	 * align:, 
	 * formatter: edit,    formatter 覆盖mainCode
	 * mainCode: true, 自动添加formatter
	 * mainCodeUrl:    配置 跳转url  自动添加 默认 id 参数
	 * }],
	 * 
	 * grid其他参数将覆盖默认设置
	 * 
	 * }
	 * 
	 */
	
	grid:function(grid_def) {
		
		
				
		for ( var k in t_module.defaltGridConf) {
			
			if(grid_def[k]==undefined){
				
				grid_def[k]=t_module.defaltGridConf[k];
				
			}	
		}
		
		
		for ( var i in grid_def.colModel) {
			
			var cm=grid_def.colModel[i];
			
			if(cm.mainCode){
				
				if(!cm.formatter){
				
				var mcUrl= cm.mainCodeUrl;
				
				cm.formatter=function(val, index, row){
					
					return  t_module.mcFmt_temp(mcUrl,val, index, row);
					
				}
				
				}
				
				break;
				
			}
		
			
		}
		

		t_module.createGrid(this.cotext,grid_def);

		

	}
	,
	/**
	buttons:[
		 * name
		 * ,key
		 * ,layout
		 * ,func
		 * ,type
		 * ,addclass
		 * ,style
		 * ]
		 */
	button:function(){
		
		
	} 
	,
	verifyAll:function(forms) {

		var verifsfalg = true;

		for ( var i in forms) {

			if (verifsfalg == false)
				return verifsfalg;
			var verify = forms[i].formVerifyScript;

			if (verify) {

				verifsfalg = verifsfalg
						&& formVerify[verify]($("#f_" + forms[i].modelKey)
								.val(), forms[i].modelName);

			}

		}

		return verifsfalg;

	}
	

}




$.fn.module = function (cmd,def,settings) {

   if(!settings){
	   settings={};
   }

   var _module =  new module(this,settings);

    return _module[cmd](def);

}

